from heapq import heappop, heappush
from typing import *


class Solution:
    def magicTower(self, nums: List[int]) -> int:
        if sum(nums) < 0:
            return -1
        ans = 0
        tot = 1
        q = []
        for num in nums:
            tot += num
            heappush(q, num)
            while tot < 1 and q:
                tot -= heappop(q)
                ans += 1
        return ans
